#include "RingQueue.hpp"
#include <ctime>
#include <unistd.h>

void* produce(void* args)
{
    RingQueue<int>* ring = static_cast<RingQueue<int>*>(args);
    while (1)
    {
        int data = rand() % 10;
        ring->push(data);
        cout << "pthread [" << pthread_self() << "] 生产了一个数据: " << data << endl;
        sleep(1);
    }
}

void* custom(void* args)
{
    RingQueue<int>* ring = static_cast<RingQueue<int>*>(args);
    while (1)
    {
        int data = ring->pop();
        cout << "pthread [" << pthread_self() << "] 消费了一个数据: " << data << endl;
    }
}

int main()
{
    srand((unsigned long) time(nullptr));

    RingQueue<int> ring;

    pthread_t cstm_p, pdc_p; 
    pthread_create(&cstm_p, nullptr, custom, (void*) &ring);
    pthread_create(&pdc_p, nullptr, produce, (void*) &ring);


    pthread_join(cstm_p, nullptr);
    pthread_join(pdc_p, nullptr);
    return 0;
}